package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.query.StrategyCatalogQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Copyright: Copyright (c) 2019 Super520
 * 描述：攻略分类控制器
 *
 * @package: cn.wolfcode.trip.admin.controller
 * @author: Patch
 * @date: 2019/5/24 15:55
 * 总结:
 */
@Controller
@RequestMapping("strategyCatalog")
public class StrategyCatalogController {
    @Autowired
    private IStrategyCatalogService catalogService;
    @Autowired
    private IStrategyService strategyService;

    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") StrategyCatalogQueryObject qo) {
        model.addAttribute("pageInfo", catalogService.query(qo));
        model.addAttribute("strategys", strategyService.listAll(null));
        return "strategyCatalog/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCatalog catalog) {


        JsonResult result = new JsonResult();
        try {
            catalogService.saveOrUpdate(catalog);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("亲，操作失败，请重试");
        }
        return result;
    }

    /**
     * 根据大攻略id查询指定的攻略分类
     * @param strategyId
     * @return
     */
    @RequestMapping("listByStrategyId")
    @ResponseBody
    public List listByStrategyId(Long strategyId){
        return catalogService.getByStrategyId(strategyId);
    }
}
